// pages/supplier/moneyManage/moneyManage.js
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        status:0,
        total:0
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            status:options.status,
            total:options.total
        })
    },
    returnDeposit() {
        let that = this
        wx.showLoading({
            title: "Loading..."
        });
        that.setData({
            disabledBtn:true
        })
        util.request(api.supplier.applyRefund,{}, "POST")
            .then((res) => {
                //console.log(res)
                that.setData({
                    disabledBtn:false
                })
                wx.showToast({
                    title: "退款成功",
                    icon: "success",
                });
                wx.navigateBack({
                    delta: 1,
                })
                wx.hideLoading();
            })
            .catch((err) => {
                console.log(err)
                wx.hideLoading();
                that.setData({
                    disabledBtn:false
                })
                wx.showToast({
                    title: err.message,
                    icon: "none",
                });
            });
    },
    payDeposit() {
        let that = this
        wx.showLoading({
            title: "支付中..."
        });
        that.setData({
            disabledBtn:true
        })
        util.request(api.supplier.payDeposit,{}, "POST")
            .then((res) => {
                console.log(res)
                wx.requestPayment({
                    'timeStamp': res.result.timeStamp,
                    'nonceStr': res.result.nonceStr,
                    'package': res.result.packageValue,
                    'signType': res.result.signType,
                    'paySign': res.result.paySign,
                    'success': function (res) {
                        that.setData({
                            disabledBtn:false
                        })
                        wx.hideLoading()
                        wx.navigateBack({
                          delta: 1,
                        })
                    },
                    'fail': function (res) {
                        wx.hideLoading()
                        wx.showToast({
                            title: "支付失败",
                            icon: "error"
                        })
                        that.setData({
                            disabledBtn:false
                        })
                    },
                    'complete': function (res) {
                      reject(res);
                    }
                });
                wx.hideLoading();
            })
            .catch((err) => {
                console.log(err)
                wx.hideLoading();
                that.setData({
                    disabledBtn:false
                })
                wx.showToast({
                    title: err.message,
                    icon: "none",
                });
            });
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})